<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons') // echarts theme
  import resize from './resize'
  import 'echarts-liquidfill'
  export default {
    mixins: [resize],
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '100%'
      },
      autoResize: {
        type: Boolean,
        default: true
      }
    },
    data() {
      return {
        chart: null,
        giftImageUrl: ''
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart() {
        this.chart = echarts.init(this.$el, 'macarons')
        this.chart.setOption({
          backgroundColor: '#101e44',
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b}: {c} ({d}%)'

          },
          graphic: {
            elements: [{
              type: 'image',
              style: {
                image: this.giftImageUrl,
                width: 50,
                height: 50
              },
              left: 'center',
              top: '40%'
            }]
          },
          title: {
            text: '类型分析',
            left: 'center',
            top: '50%',
            padding: [24, 0],
            textStyle: {
              color: '#fff',
              fontSize: 15,
              align: 'center'
            }
          },
          legend: {

            orient: 'horizontal',
            icon: 'circle',
            bottom: 1,
            x: 'center',
            data: ['温度', '应力', '振动', '倾斜', '声发射'],
            textStyle: {
              color: '#fff',
              fontSize: 16
            }
          },
          series: [{
            name: '设备类型',
            type: 'pie',
            hoverAnimation: false,
            legendHoverLink: false,
            radius: ['38%', '50%'],
            color: ['#006495', '#1D5F84', '#255C6D', '#3C5C67', '#40486C'],
            label: {
              normal: {
                position: 'inner'
              }
            },
            labelLine: {
              normal: {
                show: false
              }

            },
            tooltip: {
              show: false

            },

            data: [{
              value: 5,
              name: ''
            },
            {
              value: 2,
              name: ''
            },
            {
              value: 0,
              name: ''
            },
            {
              value: 3,
              name: ''
            },
            {
              value: 0,
              name: ''
            }

            ]
          },
          {
            name: '设备类型',
            type: 'pie',
            radius: ['50%', '65%'],
            color: ['#00FFFF', '#44EAB1', '#7BDD43', '#FEBE12', '#EBEC2F', '#FF7C44', '#FA3E5F', '#6635EF', '#FFAFDA'],
            labelLine: {
              normal: {
                show: true,
                length: 18,
                length2: 10,
                lineStyle: {
                  width: 2
                }
              }
            },
            label: {
              normal: {
                formatter: '{c|{c}}\n{hr|}\n{d|{d}%}',
                rich: {
                  b: {
                    fontSize: 15,
                    color: '#12EABE',
                    align: 'left',
                    padding: 4
                  },
                  hr: {
                    borderColor: '#12EABE',
                    width: '100%',
                    borderWidth: 2,
                    height: 0
                  },
                  d: {
                    fontSize: 15,
                    color: '#fff',
                    align: 'left',
                    padding: 4
                  },
                  c: {
                    fontSize: 15,
                    color: '#fff',
                    align: 'left',
                    padding: 4
                  }
                }
              }
            },
            data: [{
              value: 5,
              name: '温度'
            },
            {
              value: 2,
              name: '应力'
            },
            {
              value: 0,
              name: '振动'
            },
            {
              value: 3,
              name: '倾斜'
            },
            {
              value: 0,
              name: '声发射'
            }
            ]
          }
          ]
        }
        )
      }
    }
  }
</script>

<style scoped>

</style>
